package Offer.offer2019;

import domain.TreeNode;

import java.util.LinkedList;

/**
 * 树的层序遍历
 * @author: leiwenkang
 * @date: 2019/5/11
 * @time: 20:19
 */
public class Offer23 {

    public void layerTraverse(TreeNode root) {
        if (root == null) {
            return;
        }

        LinkedList<TreeNode> list = new LinkedList<>();
        list.add(root);
        while (!list.isEmpty()) {
            TreeNode node = list.remove();
            System.out.println(node.val);

            if (node.left != null) {
                list.add(node.left);
            }

            if (node.right != null) {
                list.add(node.right);
            }
        }
    }
}
